#include <inc/mmu.h>

	# vectors.S sends all traps here.
.globl alltraps
alltraps:
	# Your code here:
	#
	# Hint: you should build trap frame, set up data segments and then
	# call trap(tf)
	# Q: Why to push two long word values in vector.S
	pushw $0
	pushw %ds
	pushw $0
	pushw %es
	pushw $0
	pushw %fs
	pushw $0
	pushw %gs
	pushl %eax
	pushl %ecx
	pushl %edx
	pushl %ebx
	pushl $0
	pushl %ebp
	pushl %esi
	pushl %edi
	pushl %esp
	call trap
	addl $4, %esp

	# Return falls through to trapret...
.globl trapret
trapret:
	# Restore registers.
	# Your code here:
	popl %edi
	popl %esi
	popl %ebp
	popl %eax
	popl %ebx
	popl %edx
	popl %ecx
	popl %eax
	popw %gs
	addl $2, %esp
	popw %fs
	addl $2, %esp
	popw %es
	addl $2, %esp
	popw %ds
	addl $0xa, %esp
	iret
